package com.zrkj.controller;

import com.zrkj.entity.TSysUserRole;
import com.zrkj.entity.vo.Result;
import com.zrkj.service.ITSysUserRoleService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : 国良
 * @className : TSysUserRoleController
 * @package: com.ha.controller
 * @description : 用户关联角色表 前端控制器
 * @date :  2021-05-14
 */
@RestController
@RequestMapping(value = "/tSysUserRole")
@Api(tags = "用户关联角色表")
public class TSysUserRoleController {
    private final ITSysUserRoleService itSysUserRoleService;

    public TSysUserRoleController(ITSysUserRoleService itSysUserRoleService) {
        this.itSysUserRoleService = itSysUserRoleService;
    }

    /**
     * 添加
     *
     * @param tSysUserRole
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody TSysUserRole tSysUserRole) {
        return itSysUserRoleService.add(tSysUserRole);
    }

    /**
     * 更新
     *
     * @param tSysUserRole
     * @return
     */
    @PutMapping(value = "/update")
    public Result<Boolean> update(@RequestBody TSysUserRole tSysUserRole) {
        return itSysUserRoleService.update(tSysUserRole);
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/delete")
    public Result<Boolean> delete(@RequestParam(value = "ids") String ids) {
        String[] idsArray = ids.split(",");
        List<Long> idList = new ArrayList<>();
        for (String id : idsArray) {
            idList.add(Long.valueOf(id));
        }
        return itSysUserRoleService.delete(idList);
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getById/{id}")
    public Result<TSysUserRole> getById(@PathVariable(value = "id") Long id) {
        return itSysUserRoleService.getById(id);
    }

    /**
     * 查询列表
     *
     * @param tSysUserRole
     * @return
     */
    @PostMapping(value = "/queryList")
    public Result<List<TSysUserRole>> queryList(@RequestBody TSysUserRole tSysUserRole) {
        return itSysUserRoleService.queryList(tSysUserRole);
    }

}
